package PictureWork;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

import com.ibm.icu.text.SimpleDateFormat;

public class TurnFramePic 
{
	PictureDeal picturedeal=new PictureDeal();
	public TurnFramePic() throws IOException
	{
		BufferedImage  bi = new BufferedImage(picturedeal.frame.getWidth(),picturedeal.frame.getHeight(), BufferedImage.TYPE_INT_ARGB);
		Graphics2D  g2d = bi.createGraphics();
		picturedeal.frame.paint(g2d);
		String fileName = TurnFramePic.getRandomFileName();
		ImageIO.write(bi, "JPG", new File("D:\\DIMA",fileName+".JPG"));
	}
	
    public static String getRandomFileName() 
    {  
        SimpleDateFormat simpleDateFormat;  
        simpleDateFormat = new SimpleDateFormat("yyyyMMdd");  
        Date date = new Date();  
        String str = simpleDateFormat.format(date);  
        Random random = new Random();  
        int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数  
        return rannum + str;// 当前时间  
    } 
	 public static void main(String[] args)
	 {
	        try
	        {
				new TurnFramePic();
				System.out.println("打印成功");
				JOptionPane.showMessageDialog(null, "生成图片成功 ", "生成图片", JOptionPane.ERROR_MESSAGE);
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
	    } 

}